
public class Demo {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()-> {
           while(!Thread.currentThread().isInterrupted()) {
               System.out.println("程序运行中........");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   //e.printStackTrace();

                   //1.立即退出
                   //break;

                   //2.等一会退出
                  /* try {
                       Thread.sleep(2000);
                   } catch (InterruptedException ex) {
                       ex.printStackTrace();
                   }
                   break;*/

                   //3.不退出  什么也不写
               }
           }
        });

        t.start();

        //5s后一会停止创建的线程
       Thread.sleep(5000);
       t.interrupt();


    }
    public static  boolean Fly = true;
    public static void main3(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            while(Fly) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("程序运行中........");
            }
        });
        thread.start();
        Thread.sleep(5000);
        Fly = false;
    }
    public static void main2(String[] args) {
        Thread t = new Thread(() -> {
                System.out.println("Hello World");

        },"我的线程");
        t.start();

        System.out.println(t.getId());
        System.out.println(t.getName());
        System.out.println(t.getPriority());
        System.out.println(t.getState());
        System.out.println(t.isDaemon());
        System.out.println(t.isAlive());
    }
    public static void main1(String[] args) {
        Thread t = new Thread(() -> {
           while(true) {
               System.out.println("Hello World");
           }
        },"我的线程");
        t.start();

        while(true) {
            System.out.println("Hello Main");
        }
    }
}
